<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>拉货列表</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">

                <span>主单号：</span><input id="keyMasterBillCode" name="keyMasterBillCode" emptyText="请输入主单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="主单号不能为空" />
                <span class="separator"></span>
                <span>主单类型：</span><input id="keyMasterBillTypeId" name="keyMasterBillTypeId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择主单类型"/>
                <span class="separator"></span>
                <span>拉货日期：</span>
                <input id="keyPullStartDate" name="keyPullStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyPullEndDate" name="keyPullEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>

                <div style="margin-top: 5px"></div>

                <% if(so.hasPermission("bMasterBillPull:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchMasterPull()">查询</a>
                <% } %>

                <% if(so.hasPermission("bMasterBillPull:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <% if(so.hasPermission("bMasterBillPull:pullUpdate")){%>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-edit" onclick="showMasterBillPullUpdate()">主单拉货修改</a>
                <% } %>

                <span class="separator"></span>
                <% if(so.hasPermission("bMasterBillPull:download")){%>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="主单拉货信息表"/>
                <% } %>

            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/master_bill_manage/pull/queryMasterBillPull" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 sortField="createTime"
                 sortOrder="desc"
                 onshowrowdetail="showRowDetail">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div type="expandcolumn" ></div>
                    <div field="masterBillId" width="140" headerAlign="center" align="center" allowSort="true" renderer="showMasterBillRender" >主单号</div>
                    <div field="masterBillTypeId" width="80" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">主单类型</div>
                    <div field="pullDisposeNumber" width="140" headerAlign="center" align="right" allowSort="true"  summaryType="sum">拉货处置件数</div>
                    <div field="pullDisposeActualWeight" width="140" headerAlign="center" align="right" allowSort="true"  summaryType="sum">拉货处置实重</div>
                    <div field="pullDisposeChargeableWeight" width="140" headerAlign="center" align="right" allowSort="true"  summaryType="sum">拉货处置计重</div>
                    <div field="pullDisposeVolume" width="140" headerAlign="center" align="right" allowSort="true" summaryType="sum">拉货处置体积</div>
                    <div field="pullDisposeTransportCostAmount" width="140" headerAlign="center" align="right" allowSort="true" summaryType="sum">拉货运费调整金额</div>
                    <div field="pullDisposeGroundAmount" width="140" headerAlign="center" align="right" allowSort="true" summaryType="sum">拉货地面操作费调整金额</div>
                    <div field="pullDisposeAirlinesAddCostAmount" width="140" headerAlign="center" align="right" allowSort="true" summaryType="sum">拉货航空附加费调整金额</div>
                    <div field="pullDisposeOtherChargesAmount" width="140" headerAlign="center" align="right" allowSort="true" summaryType="sum">拉货其他费用调整金额</div>
                    <div field="pullDisposeAmount" width="140" headerAlign="center" align="right" allowSort="true" renderer="public_moneyRenderer" summaryType="sum">拉货调整总金额</div>
                    <div field="pullDisposeComment" width="140" headerAlign="center" align="left" >拉货处置说明</div>
                    <div field="createTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">创建时间</div>
                    <div field="createUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建用户</div>
                </div>
            </div>
        </div>

        <!-- 子表 -->
        <div id="detailDiv" style="display:none; margin-left: 60px">
            <div id="detailGrid" class="mini-datagrid" style="width:1700px;height:150px;"
                 url="${base}/pages/master_bill_manage/pull/detail/queryPullDetailList">
                <div property="columns">
                    <div field="nativeBillId" width="50" headerAlign="center" align="center"  renderer="showNativeBillRender" >分单号</div>
                    <div field="pullNumber" width="70" headerAlign="center" align="right" >拉货件数</div>
                    <div field="pullActualWeight" width="70" headerAlign="center" align="right" >拉货实重</div>
                    <div field="pullChargeableWeight" width="70" headerAlign="center" align="right" >拉货计重</div>
                    <div field="pullVolume" width="70" headerAlign="center" align="right" >拉货体积</div>
                    <div field="pullAmount" width="70" headerAlign="center" align=" right" >拉货调整金额</div>
                    <div field="pullComment" width="140" headerAlign="center" align=" left" >拉货备注</div>
                    <div field="pullDisposeReasonIds" width="180" headerAlign="center" align="left" allowSort="true"  data-options='{cacheName:"sysDic"}' renderer="commonRenderXtDicCacheNameByIds">拉货原因</div>
                    <div field="pullDisposeId" width="80" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">拉货处置类型</div>
                    <div field="pullDisposeAirportId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airport"}' renderer="commonRender">始发机场</div>
                    <div field="pullDisposeAirlinesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司</div>
                    <div field="pullDisposeFlightDate" width="100" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">拉货处置日期</div>
                    <div field="pullDisposeFlightName" width="80" headerAlign="center" align="center" allowSort="true" >拉货处置班次</div>

                </div>
            </div>
        </div>



        <div id="masterBillPullUpdatePanel" class="mini-window" title="主单拉货修改" style="width:900px;height:450px;"
             showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
             showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">

            <div property="footer" style="padding:10px;text-align: right">
                <a  class="mini-button" iconCls="icon-save" onclick="masterBillPullUpdate()">保存</a>
                <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('masterBillPullUpdatePanel')">关闭</a>
            </div>

            <div id="masterBillPullForm">
                <input id="id" name="id" emptyText="主单拉货ID"  class="mini-hidden" required="true" requiredErrorText="主单拉货ID不能为空" enabled="false" />
                <span>主单号:</span>
                <input id="masterBillId" name="masterBillId" emptyText="主单号"  class="mini-textbox" required="false" requiredErrorText="主单号不能为空" enabled="false" style="width: 200px;" />
                <span>主单类型：</span>
                <input id="masterBillTypeId" name="masterBillTypeId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         enabled="false"  required="true" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择主单类型"/>

                <div style="margin-top: 5px"></div>
                <span style="color: red;font-weight: bold">主单处置信息:</span>
                <div style="margin-top: 5px"></div>
                <span>件数:</span>
                <input id="pullDisposeNumber" name="pullDisposeNumber" emptyText="主单处置件数"  class="mini-textbox" required="true" requiredErrorText="主单处置件数不能为空" enabled="false"  />

                <span>实重:</span>
                <input id="pullDisposeActualWeight" name="pullDisposeActualWeight" emptyText="主单处置实重"  class="mini-textbox" required="true" requiredErrorText="主单处置实重不能为空" enabled="false"  />

                <span>计重:</span>
                <input id="pullDisposeChargeableWeight" name="pullDisposeChargeableWeight" emptyText="主单处置计重"  class="mini-textbox" required="true" requiredErrorText="主单处置计重不能为空" enabled="false" />

                <span>体积:</span>
                <input id="pullDisposeVolume" name="pullDisposeVolume" emptyText="主单处置体积"  class="mini-textbox" required="false" requiredErrorText="主单处置体积不能为空" enabled="true"  />

                <div style="margin-top: 5px"></div>
                <span style="color: red;font-weight: bold">主单拉货调整费用信息:</span>
                <div style="margin-top: 5px"></div>
                <span>航空运费:</span>
                <input id="pullDisposeTransportCostAmount" name="pullDisposeTransportCostAmount" emptyText="主单拉货调整运费" value="0"  vtype="float" class="mini-textbox" required="true" requiredErrorText="主单拉货调整运费不能为空" enabled="true" onvaluechanged="calcTotalCostAmount" />

                <span>地面操作费:</span>
                <input id="pullDisposeGroundAmount" name="pullDisposeGroundAmount" emptyText="主单拉货调整地面操作费" value="0"  vtype="float"  class="mini-textbox" required="true" requiredErrorText="主单拉货调整地面操作费不能为空" enabled="true" onvaluechanged="calcTotalCostAmount" />

                <span>航空附加费:</span>
                <input id="pullDisposeAirlinesAddCostAmount" name="pullDisposeAirlinesAddCostAmount" emptyText="主单拉货调整航空附加费" value="0" vtype="float" class="mini-textbox" required="true" requiredErrorText="主单拉货调整航空附加费不能为空" enabled="true" onvaluechanged="calcTotalCostAmount" />

                <span>其他费用:</span>
                <input id="pullDisposeOtherChargesAmount" name="pullDisposeOtherChargesAmount" emptyText="主单拉货调整其他费用" value="0" vtype="float"  class="mini-textbox" required="true" requiredErrorText="主单拉货调整其他费用不能为空" enabled="true" onvaluechanged="calcTotalCostAmount" />

                <div style="margin-top: 5px"></div>
                <span>调整总金额:</span>
                <input id="pullDisposeAmount" name="pullDisposeAmount" emptyText="主单拉货调整总金额" value="0" vtype="float" class="mini-textbox" required="true" requiredErrorText="主单拉货调整总金额不能为空" enabled="false" />

                <div style="margin-top: 5px"></div>
                <span>主单拉货备注:</span>
                <textarea id="pullDisposeComment" name="pullDisposeComment" class="mini-textarea" style="width: 80%;height: 80px" emptyText="请输入主单拉货备注信息"  required="true"></textarea>

                <div style="margin-top: 5px"></div>
                <a  class="mini-button" iconCls="icon-ok" onclick="generatePullDisposeComment()">生成主单拉货备注</a>

            </div>

        </div>


        <script type="text/javascript">
            mini.parse();

            let keyMasterBillCode = mini.get("keyMasterBillCode");
            let keyMasterBillTypeId = mini.get("keyMasterBillTypeId");
            let keyOpenBillStartDate = mini.get("keyOpenBillStartDate");
            let keyOpenBillEndDate = mini.get("keyOpenBillEndDate");

            let grid = mini.get("datagrid1");


            let detailDiv = document.getElementById("detailDiv");

            let detailGrid = mini.get("detailGrid");

            let masterBillPullUpdatePanel = mini.get("masterBillPullUpdatePanel");

            let masterBillPullForm = new mini.Form("#masterBillPullForm");

            let masterBillTypeId = mini.get("masterBillTypeId");

            let pullDisposeTransportCostAmount = mini.get("pullDisposeTransportCostAmount");
            let pullDisposeGroundAmount = mini.get("pullDisposeGroundAmount");
            let pullDisposeAirlinesAddCostAmount = mini.get("pullDisposeAirlinesAddCostAmount");
            let pullDisposeOtherChargesAmount = mini.get("pullDisposeOtherChargesAmount");
            let pullDisposeAmount = mini.get("pullDisposeAmount");
            let pullDisposeComment = mini.get("pullDisposeComment");





            $(function () {

                // 运输种类下拉列表
                let keyMasterBillTypeIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_MASTER_BILL_TYPE");
                keyMasterBillTypeId.load(keyMasterBillTypeIdJsonData);

                masterBillTypeId.load(public_deepClone(keyMasterBillTypeIdJsonData));

                // 加载列表数据
                grid.load();
            });

            function clearSearch(){
                let form = new mini.Form("#queryForm");
                form.clear();
            }

            /**
             * 根据查询条件查询分单
             */
            function searchMasterPull(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                grid.load(data);
            }

            /**
             * 加载拉货明细
             * @param e
             */
            function showRowDetail(e){
                let grid = e.sender;
                let row = e.record;

                let td = grid.getRowDetailCellEl(row);
                td.appendChild(detailDiv);

                detailDiv.style.display = "block";

                detailGrid.load({masterBillPullId: row.id});
            }


            /**
             * 261,260,航空主单,航空主单
             262,260,汽运主单,汽运主单
             * @type {{auto: number, air: number}}
             */
            let masterBillType ={air:261,auto:262};

            // 展示主单号时显示其超链接
            function showMasterBillRender(e){
                // renderer="showMasterBillRender"

                let masterBillId = e.value;
                let billType = e.record.masterBillTypeId;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewMasterBill(\""+ masterBillId +"\"," + billType + ")'>" + masterBillId + "</a>";

                return htmlStr;
            }

            function showViewMasterBill(masterBillId,billType){
                let tabUrl= "";
                let tabTitle = "";
                if(billType==masterBillType.air){
                    tabUrl="${base}/pages/master_bill_manage/flight/showUpdateMasterBill?opType=view&id=" + masterBillId;
                    tabTitle = "航空主单查看";
                }
                else{
                    tabUrl="${base}/pages/master_bill_manage/auto/showUpdateMasterBill?opType=view&id=" + masterBillId;
                    tabTitle = "汽运主单查看";
                }

                parent.window.addTabToMainPage(tabTitle,tabTitle,tabUrl);
            }


            function showNativeBillRender(e){
                //  renderer="showNativeBillRender"
                let nativeBillId = e.value;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewNativeBill(\""+ nativeBillId +"\")'>" + nativeBillId + "</a>";
                return htmlStr;
            }

            function showViewNativeBill(nativeBillId){
                let tabUrl="${base}/pages/native_bill_manage/showUpdateBill?opType=view&id=" + nativeBillId;
                parent.window.addTabToMainPage("分单查看","分单查看",tabUrl);
            }


            /**
             * 主单拉货更新面板显示
             */
            function showMasterBillPullUpdate(){
                let masterBillPullObjs = grid.getSelecteds();
                if(masterBillPullObjs.length==0){
                    showAlert("请选择需要编辑的对象！");
                    return;
                }

                if(masterBillPullObjs.length>1){
                    showAlert("编辑时请选择一行！");
                    return;
                }

                let masterBillPullObj = masterBillPullObjs[0];

                masterBillPullForm.setData(masterBillPullObj);
                // 弹出添加窗口
                public_showModelAtPos("masterBillPullUpdatePanel", "center", "middle");


            }

            function calcTotalCostAmount(){
                let pullDisposeTransportCostAmountValue = public_toNumber(pullDisposeTransportCostAmount.getValue(),0);
                let pullDisposeGroundAmountValue = public_toNumber(pullDisposeGroundAmount.getValue(),0);
                let pullDisposeAirlinesAddCostAmountValue = public_toNumber(pullDisposeAirlinesAddCostAmount.getValue(),0);
                let pullDisposeOtherChargesAmountValue = public_toNumber(pullDisposeOtherChargesAmount.getValue(),0);
                pullDisposeAmount.setValue(public_toNumber(pullDisposeTransportCostAmountValue+pullDisposeGroundAmountValue +pullDisposeAirlinesAddCostAmountValue + pullDisposeOtherChargesAmountValue,0));
            }

            function generatePullDisposeComment(){
                let pullDisposeCommentValue = pullDisposeComment.getValue();
                let startIndex = pullDisposeCommentValue.indexOf("【主单拉货调整金额】");
                let endIndex = pullDisposeCommentValue.indexOf("【分单拉货备注】");

                let pullDisposeTransportCostAmountValue = public_toNumber(pullDisposeTransportCostAmount.getValue(),0);
                let pullDisposeGroundAmountValue = public_toNumber(pullDisposeGroundAmount.getValue(),0);
                let pullDisposeAirlinesAddCostAmountValue = public_toNumber(pullDisposeAirlinesAddCostAmount.getValue(),0);
                let pullDisposeOtherChargesAmountValue = public_toNumber(pullDisposeOtherChargesAmount.getValue(),0);
                let pullDisposeAmountValue = public_toNumber(pullDisposeAmount.getValue(),0);

                let str = pullDisposeCommentValue.substring(startIndex,endIndex);
                //
                let str1= "【主单拉货调整金额】运费:" + pullDisposeTransportCostAmountValue
                    + ", 地面操作费:" + pullDisposeGroundAmountValue
                    + ", 航空附加费:" + pullDisposeAirlinesAddCostAmountValue
                    + ", 其他费用:" + pullDisposeOtherChargesAmountValue
                    + ", 总调整金额:" + pullDisposeAmountValue + ", ";
                let result =  pullDisposeCommentValue.replace(str,str1);
                pullDisposeComment.setValue(result);
            }

            /**
             * 主单拉货保存
             */
            function masterBillPullUpdate(){

                masterBillPullForm.validate();
                if (masterBillPullForm.isValid() == false) {
                    return;
                }

                mini.confirm("确定修改主单拉货调整信息？", "拉货提示",
                    function (action) {
                        if (action == "ok") {
                            submitPullData();
                        }
                    }
                );
            }

            /**
             * 提交主单拉货更新数据，并做相关操作
             */
            function submitPullData(){
                let masterBillPullFormData = masterBillPullForm.getData(true);
                let pullUrl = "${base}/pages/master_bill_manage/pull/updatePullData";
                let ret = public_getServerData(pullUrl, masterBillPullFormData);
                showAlert(ret.message,function (){
                    if(ret.ok){
                        grid.reload();
                        // 关闭主单拉货窗口
                        public_onCancel("masterBillPullUpdatePanel");
                    }
                });
            }

        </script>



    </body>
</html>